package com.payment.ktb.utils;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.flyco.animation.BaseAnimatorSet;
import com.flyco.animation.BounceEnter.BounceTopEnter;
import com.flyco.animation.SlideExit.SlideBottomExit;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.MaterialDialog;
import com.payment.ktb.Interface.AlertInterface;
import com.payment.ktb.R;


/**
 * Created by syd on 2015/12/19.
 */
public class AlertDialogUtils {


    private static BaseAnimatorSet mBasIn;
    private static BaseAnimatorSet mBasOut;

    static {
        mBasIn = new BounceTopEnter();
        mBasOut = new SlideBottomExit();
    }



    /**
     *只含有一个button的AlertDialog，点击确定后，默认取消
     * @param context
     * @param alertMessage
     */

    public static  void  showAlertDialog(Context context,String alertMessage) {
        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog//
                .btnNum(1)
                .content(alertMessage)//
                .btnText("确定")//
                .showAnim(mBasIn)//
                .dismissAnim(mBasOut)//
                .show();

        dialog.setOnBtnClickL(new OnBtnClickL() {
            @Override
            public void onBtnClick() {
                dialog.dismiss();
            }
        });

    }


    /**
     *只含有一个button的AlertDialog，点击确定后，默认取消
     * @param context
     * @param alertMessage
     */

    public static  void  showAlertDialogCopy(Context context,String alertMessage) {

        final AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.getWindow().setContentView(R.layout.alertdialog_type_one);
        ((TextView) dialog.getWindow().findViewById(R.id.tv_dialog_type_one_message)).setText(alertMessage);
        ((Button) dialog.getWindow().findViewById(R.id.btn_dialog_type_one_confirm)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });

    }


    /**
     *只含有一个button的AlertDialog，点击确定后，执行回调函数的事件
     * @param context
     * @param alertMessage
     * @param alertInterface
     */

    public static  void  showAlertDialog(Context context,String alertMessage,final AlertInterface alertInterface) {


        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog//
                .btnNum(1)
                .content(alertMessage)//
                .btnText("确定")//
                .showAnim(mBasIn)//
                .dismissAnim(mBasOut)//
                .show();

        dialog.setOnBtnClickL(new OnBtnClickL() {
            @Override
            public void onBtnClick() {
                dialog.dismiss();
                alertInterface.confirm(dialog);

            }
        });

    }



    /**
     *只含有一个button的AlertDialog，点击确定后，执行回调函数的事件
     * @param context
     * @param alertMessage
     * @param alertInterface
     */

    public static  void  showAlertDialogCopy(Context context,String alertMessage,final AlertInterface alertInterface) {

        final AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.getWindow().setContentView(R.layout.alertdialog_type_one);
        ((TextView) dialog.getWindow().findViewById(R.id.tv_dialog_type_one_message)).setText(alertMessage);
        ((Button) dialog.getWindow().findViewById(R.id.btn_dialog_type_one_confirm)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertInterface.confirm(dialog);
            }
        });

    }


    /**
     *返回有两个按钮的dialog
     * @param context
     * @param alertMessage
     * @param btnCancel
     * @param btnConfirm
     * @param confirmAlertInterface
     */

    public static  void  showAlertDialog(Context context,String alertMessage,String btnCancel,String btnConfirm, final AlertInterface confirmAlertInterface) {



        final MaterialDialog dialog = new MaterialDialog(context);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.content(alertMessage)//
                .btnText(btnCancel, btnConfirm)//
                .showAnim(mBasIn)//
                .dismissAnim(mBasOut)//
                .show();

        dialog.setOnBtnClickL(
                new OnBtnClickL() {//left btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {//right btn click listener
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                        confirmAlertInterface.confirm(dialog);
                    }
                }
        );

    }



    /**
     *返回有两个按钮的dialog
     * @param context
     * @param alertMessage
     * @param btnCancel
     * @param btnConfirm
     * @param confirmAlertInterface
     */

    public static  void  showAlertDialogCopy(Context context,String alertMessage,String btnCancel,String btnConfirm, final AlertInterface confirmAlertInterface) {



        final AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.getWindow().setContentView(R.layout.alertdialog_type_two);
        ((TextView)dialog.getWindow().findViewById(R.id.tv_dialog_type_two_message)).setText(alertMessage);
        ((Button)dialog.getWindow().findViewById(R.id.btn_dialog_type_two_cancel)).setText(btnCancel);
        ((Button)dialog.getWindow().findViewById(R.id.btn_dialog_type_two_confirm)).setText(btnConfirm);
        ((Button)dialog.getWindow().findViewById(R.id.btn_dialog_type_two_cancel)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        ((Button)dialog.getWindow().findViewById(R.id.btn_dialog_type_two_confirm)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               confirmAlertInterface.confirm(dialog);
            }
        });
    }



}
